//
// Created by LH on 2017/9/6.
//

#include "iostream"
using namespace std;

int n, m;
int head[50];
int nx[50];	//next
int map[50][3];
int main()
{
    cin >> n >> m;
    for (int i=0;i<50;i++)
    {
        head[i] = -1;
    }
    for (int t=1;t<=m;t++)
    {
        int t1, t2, t3;
        cin >> t1 >> t2 >> t3;
        map[t][0] = t1;
        map[t][1] = t2;
        map[t][2] = t3;
        nx[t] = head[t1];
        head[t1] = t;
    }
    for (int j = 1; j <=n; j++)
    {
        int k = head[j];
        while (k!=-1)
        {
            cout << map[k][0] << map[k][1] << map[k][2]<<endl;
            k = nx[k];
        }
        cout << endl;
    }
    return 0;
}
/*
4 5
1 4 9
4 3 8
1 2 5
2 4 6
1 3 7
*/